//
// Created by wkm on 2024-04-13.
//

#include "x3time.h"

void x3time::prc_x3time() {
    if (reset) {
        next_result = 0;
        x2_reset = true;
        x2_start = false;
        done = waiting_task; //快速响应
        next_done = waiting_task;
        x2_compute_times.write(1);
    }

    if (start && done == waiting_task) {
//        result = input_data;
        next_result = input_data;
        x2_reset = false;
        next_done = preparing_task;
    }

    if (done == preparing_task) {
        x2_start = true;
        next_done = computing_task;
    }

    if (done == computing_task) {
        if (x2_done == task_finished) {
            next_result = result.read() ^ x2_result.read();
//            cout << hex << "x3done:" << input_data << "," << next_result << endl;
            next_done = task_finished;
        }
    }

    result = next_result;
    done = next_done;
}